package com.example.blew.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.blew.demo.mapper.TableAddData;
import com.example.blew.demo.mapper.TableMapper;
import com.example.blew.demo.model.TablePo;
import com.example.blew.demo.service.TableService;
import com.example.blew.demo.uitl.DataAdd;
import com.example.blew.demo.uitl.DataAddFactory;
import com.example.blew.demo.uitl.RrturnMesage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author chaodong.zeng@pcitc.com
 * @since 2022/9/10
 */
@Service
public class TableServiceImpl implements TableService {

    @Resource
    TableMapper tableMapper;

    @Resource
    TableAddData tableAddData;

    @Resource
    DataAddFactory dataAddFactory;

    @Override
    public int insertUser(TablePo tablePo) {
        int insert = tableMapper.insert(tablePo);
        return insert;
    }

    @Override
    public RrturnMesage selectPage(int current, int size) {
        Page<TablePo> page = new Page(current, size);
        QueryWrapper<TablePo> queryWrapper = new QueryWrapper<>();
        tableMapper.selectPage(page, queryWrapper);
        return RrturnMesage.ok().data("current", page.getCurrent()).data("pages", page.getPages()).data("records", page.getRecords()).data("size", page.getSize()).data("total", page.getTotal());
    }

    @Override
    public int addData() {
        DataAdd dataAdd = new DataAdd();
        int insert = 0;
        dataAdd = dataAddFactory.getDataAdd();
        insert = tableAddData.insert(dataAdd);
        return insert;
    }
}